
#if TARGET_IPHONE_SIMULATOR
    #define HY_HTTP_NET_TIMEOUT 300.f
#else
    #define HY_HTTP_NET_TIMEOUT 300.f
#endif

#import <Foundation/Foundation.h>
#import "HYRequestDefine.h"
#import <AFNetworking/AFNetworking.h>
#import <AFNetworking/AFNetworkActivityIndicatorManager.h>

typedef void(^HYHttpRequestSuccess)(id responseObject);
typedef void(^HYHttpRequestError)(NSError *error,NSString *errorStr);
typedef void(^HYHttpLoginError)(NSError *error,NSString *errorStr);
typedef void(^requestCompletion)(id responseObject, NSError *error, NSString *errorStr);


@interface HYRequestBaseHelper : NSObject

@property (nonatomic,strong)AFHTTPSessionManager *manager;
@property (nonatomic,assign)AFNetworkReachabilityStatus status;

/** 服务器时间 */
@property (nonatomic,assign) NSTimeInterval serverTime;
@property (nonatomic,strong) NSDictionary <NSString *,NSString *> *urlPageCodeMap;
@property (nonatomic,strong)  NSDictionary <NSString *,NSString *>*urlIgnorLoading;

/// 解析url
/// @param jsonUrl json地址
/// @param successBlock 成功回调
/// @param failureBlock 失败回调
+ (void)parseJsonUrl:(NSString *)jsonUrl success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

/**
 *  GET请求
 *
 *  @param url          请求地址
 *  @param parameters   请求拼接所需参数
 *  @param successBlock 请求 成功后回调操作
 *  @param failureBlock 请求失败后回调操作
 */
+ (NSURLSessionDataTask *)GET:(NSString *)url parameters:(id)parameters success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (NSURLSessionDataTask *)GET:(NSString *)url parameters:(id)parameters headers:(NSDictionary *)headers success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (void)POST:(NSString *)url parameters:(id)parameters success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (NSURLSessionDataTask *)POST:(NSString *)url parameters:(id)parameters headers:(NSDictionary *)headers success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (void)PUT:(NSString *)url parameters:(id)parameters success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (void)DELETE:(NSString *)url parameters:(id)parameters success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (void)DELETE:(NSString *)url parameters:(id)parameters headers:(NSDictionary *)headers success:(HYHttpRequestSuccess)successBlock failure:(HYHttpRequestError)failureBlock;

+ (BOOL)isNetworkAvailable;

+ (NSSet *)defaultAcceptableContentTypes;

@end

@interface AFHTTPSessionManager (HY)

+ (AFHTTPSessionManager *)HY_defaultManagerWithURL:(NSString *)url;

@end

@interface HYRequestBaseHelper (GET)

/**
 一个参数多个返回值get请求

 @param url             请求地址
 @param parameters      请求参数
 @param headers         请求header
 @param completionBlock 数据返回的回调
 
 */
+ (NSURLSessionDataTask *)GET:(NSString *)url parameters:(id)parameters headers:(NSDictionary *)headers completion:(requestCompletion)completionBlock;

@end

@interface HYRequestBaseHelper (POST)

/**
 一个参数多个返回值Post请求
 
 @param url             请求地址
 @param parameters      请求参数
 @param headers         请求header
 @param completionBlock 数据返回的回调
 
 */
+ (NSURLSessionDataTask *)POST:(NSString *)url parameters:(id)parameters headers:(NSDictionary *)headers completion:(requestCompletion)completionBlock;

@end

@interface HYRequestBaseHelper (HYTDownload)

/// 下载文件
/// @param url 文件URL
/// @param parameters 参数
/// @param headers 请求头
/// @param downloadProgressBlock 进度
/// @param destination 存放位置
/// @param completionHandler 完成的回调
+ (NSURLSessionDownloadTask *)download:(NSString *)url
                            parameters:(id)parameters
                               headers:(NSDictionary *)headers
                              progress:(void (^)(NSProgress *downloadProgress))downloadProgressBlock
                           destination:(NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
                     completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError * error))completionHandler;

@end


